/**
 * 
 */
package rabbitmqTest;
import java.io.IOException;
import java.util.concurrent.TimeoutException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
/**
 * @author yanglei
 *
 * 2018年1月14日
 */
public class MessageSender {
	 public final static String QUEUE_NAME="rabbitMQ.test";

	    public static void main(String[] args) throws IOException, TimeoutException {
	        //创建连接工厂
	    	   com.rabbitmq.client.ConnectionFactory factory = new com.rabbitmq.client.ConnectionFactory();
	    	   factory.setHost("106.14.126.115");
	    	   factory.setPort(5672);
	    	   factory.setUsername("admin");
	    	   factory.setPassword("123456");
	        
	        //创建一个连接  
	        Connection connection = factory.newConnection();  
	        //创建一个频道  
	        Channel channel = connection.createChannel();  
	        //指定一个队列  
	        channel.queueDeclare(QUEUE_NAME, false, false, false, null);  
	        //发送的消息  
	        String message = "hello world!";  
	        //往队列中发出一条消息  
	        channel.basicPublish("", QUEUE_NAME, null, message.getBytes());  
	        System.out.println(" [x] Sent '" + message + "'");  
	        //关闭频道和连接  
	        channel.close();  
	        connection.close();  
	    }

}
